<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Email extends MY_Controller
{
	public function __construct()
	{
		parent::__construct();
		$this->load->model('Email_model', 'email');
        $login_status  = $this->check_login_status();
        if (empty($login_status)){
            redirect('/');die;
        }
	}
    public function index()
    {
        $_SESSION['sidebar'] = "email";  
        $per_page = $this->input->get('per_page') ? $this->input->get('per_page') : 0;
        $limit = 20;
        $total_rows = $this->email->getMyEmailListCnt();
        $base_url = '/email/index?';
        $page_links = $this->create_page_links($base_url,$total_rows,$limit);
        $emailList = $this->email->getMyEmailList(" e.id ,e.subject ,e.content ,e.addtime ,m.createtime ,m.readtime, m.from_userid, m.from_username,m.id pushid ",$per_page, $limit);
        $data = array(
            'emailList'=>$emailList,
            'page_links'=>$page_links,
            'per_page'=>$per_page,
            );
        $this->load->view("email/index", $data);
    }

    public function detail(){
        $_SESSION['sidebar'] = "email";
        $id = $this->input->get('id') ? $this->input->get('id') : 0;
        $fields = " e.id ,e.subject ,e.content ,e.addtime ,m.createtime ,m.readtime, m.from_userid, m.from_username,m.id pushid ";
        $detail = $this->email->getDetail($fields, $id);
        $this->email->setRead($detail['pushid']);
        $this->load->view("email/detail", ['detail'=>$detail]);        
    }

    //编辑上线下，删除状态
    public function delEmail(){
        $id = $this->input->post("id",true) ? $this->input->post("id",true) : 0;
        $res =$this->email->delEmail($id,$_SESSION['userInfo']['AccountID']);
        echo $res;
    }
	
}
/* End of file Index.php */
/* Location: ./application/controllers/index.php */
